home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar
/
1998
/
Sep
/
di9809am
/
Compont
/
Sample1
/
Update
/
TapiForm.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-06-29
|
10KB
|
353 lines
{ This project accompanies the article written by Alan Moore
and Ken Kyler on TAPI basics }
unit TapiForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Mask, ComCtrls, Tapi, TAPIComp;
type
TTapiCallManager = class(TForm)
PanelTop: TPanel;
Label1: TLabel;
ePhoneNum: TMaskEdit;
btnDial: TButton;
btnHangup: TButton;
cboxDevices: TComboBox;
cbLineMapper: TCheckBox;
Memo: TMemo;
StatusBar: TPanel;
ImageList: TImageList;
cboxMediaMode: TComboBox;
cboxBearerMode: TComboBox;
Panel1: TPanel;
RI: TImage;
CD: TImage;
RD: TImage;
DSR: TImage;
DTR: TImage;
CTS: TImage;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Port: TImage;
Label8: TLabel;
btnDialingProperties: TButton;
cbPulseDialing: TCheckBox;
cboxAcceptCalls: TCheckBox;
procedure btnDialClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
procedure btnHangupClick(Sender: TObject);
procedure cboxDevicesChange(Sender: TObject);
procedure cbLineMapperClick(Sender: TObject);
procedure cboxMediaModeChange(Sender: TObject);
procedure cboxBearerModeChange(Sender: TObject);
procedure btnDialingPropertiesClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
// procedure cboxAcceptCallsClick(Sender: TObject);
procedure btnAnswerCallClick(Sender: TObject);
procedure kkamTAPI1EnumerateDevices(sender: TObject;
UpdateList: TStringList);
procedure kkamTAPI1OpenLine(sender: TObject; UpdateList: TStringList);
procedure kkamTAPI1TriggerCommEvent(sender: TObject;
ACommEvent: TCommEvent; AStatus: Integer);
procedure kkamTAPI1CreateCallManager(sender: TObject;
UpdateList: TStringList);
procedure kkamTAPI1DestroyCallManager(sender: TObject;
UpdateList: TStringList);
procedure kkamTAPI1ShutdownManager(sender: TObject;
UpdateList: TStringList);
procedure kkamTAPI1Dial(sender: TObject; UpdateList: TStringList);
procedure cbPulseDialingClick(Sender: TObject);
// procedure kkamTAPI1CommThreadEvent(sender: TObject;
// ThreadAction: TThreadAction);
public
//CommStatusThread: TCommStatus;
procedure SetBitmap(Image: TImage; Index: integer);
private
{ Private declarations }
procedure PhoneNumChange;
procedure SetModemLights;
{ Public declarations }
end;
var
TapiCallManager : TTapiCallManager;
TAPICntrl: TkkamTAPI;
const
Ver = $00010004; // API version accepted (1.4) [Windows 95]
off = 0;
red = 1;
yellow = 2;
green = 3;
implementation
{$R *.DFM}
procedure TTapiCallManager.SetModemLights;
var
S : string;
begin
// load the ImageList
S := ExtractFilePath(Application.exename);
with ImageList do begin
FileLoad(rtBitMap, S + 'LEDOff.bmp', clNone); // 0
FileLoad(rtBitMap, S + 'LEDRedOn.bmp', clNone); // 1
FileLoad(rtBitMap, S + 'LEDYellowOn.bmp', clNone); // 2
FileLoad(rtBitMap, S + 'LEDGreenOn.bmp', clNone); // 3
end;
with ImageList do begin
GetBitMap(off, RI.Picture.Bitmap);
GetBitMap(off, CD.Picture.Bitmap);
GetBitMap(off, RD.Picture.Bitmap);
GetBitMap(off, DSR.Picture.Bitmap);
GetBitMap(off, DTR.Picture.Bitmap);
GetBitMap(off, CTS.Picture.Bitmap);
GetBitMap(off, Port.Picture.Bitmap);
end;
end;
procedure TTapiCallManager.btnDialClick(Sender: TObject);
var
DialResult: string;
begin
if not TAPICntrl.AutoSelectLine and (TAPICntrl.Dev < 0) then begin
// a device wasn't selected
ShowMessage('You must first select a Line device!');
Exit;
end;
DialResult := TAPICntrl.Dial;
if DialResult='Success' then
begin
btnDial.Enabled := false; // disable the dial button
btnHangup.Enabled := true; // and enable the hangup button
Memo.Lines.Add(DialResult);
end
else
ShowMessage(DialResult);
end;
procedure TTapiCallManager.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
var
TempStringList : TStringList;
begin
TempStringList := TStringList.Create;
TempStringList.Clear;
// if the custom call manager was used, make sure to free resources
if TAPICntrl.CheckLineIsOpen then
CanClose := TAPICntrl.ShutdownManager;
// Update Memo
Memo.Lines.Assign(TStrings(TempStringList));
TempStringList.Free;
end;
procedure TTapiCallManager.FormCreate(Sender: TObject);
var
S : string;
TempStringList : TStringList;
begin
{ The following code creates the TkkamTAPI component at run-time
and assigns the event handlers.
This saves you from installing the component in order to demo it.}
TAPICntrl := TkkamTAPI.Create(TapiCallManager);
with TAPICntrl do begin
OnEnumerateDevices := kkamTAPI1EnumerateDevices;
OnOpenLine := kkamTAPI1OpenLine;
OnTriggerCommEvent := kkamTAPI1TriggerCommEvent;
OnCreateCallManager := kkamTAPI1CreateCallManager;
OnDestroyCallManager := kkamTAPI1DestroyCallManager;
OnShutdownManager := kkamTAPI1ShutdownManager;
OnDial := kkamTAPI1Dial;
end;
TAPICntrl.ChangePhoneNumber(ePhoneNum.Text);
TempStringList := TStringList.Create;
btnHangup.Enabled := false; // disable the hangup button
ImageList := TImageList.Create(Application);
SetModemLights;
cboxMediaMode.ItemIndex := 3; // default to LINEMEDIAMODE_DATAMODEM
cboxBearerMode.ItemIndex := 0; // default to LINEBEARERMODE_VOICE
if not TAPICntrl.TapiInitialize then
// if we can't initialize, close
begin
//TAPI_Initialized := False; // So we don't free stuff twice
ShowMessage('Could not initialize TAPI -- closing window');
Memo.Lines.Assign(TStrings(TempStringList));
Memo.Invalidate;
TAPICntrl.Free;
TempStringList.Free;
Close;
end
else
begin
if TAPICntrl.OpenLine(False, S) then
begin
SetBitMap(TapiCallManager.Port, green);
ImageList.GetBitMap(green,
Port.Picture.Bitmap);
end;
Memo.Lines.AddStrings(TStrings(TempStringList));
// fill the combobox with the available devices
TempStringList.Free;
TAPICntrl.EnumerateDevices;
end;
StatusBar.Caption := cboxDevices.Text;
end;
procedure TTapiCallManager.FormDestroy(Sender: TObject);
begin
// if ImageList<> Nil then
// ImageList.Free;
end;
procedure TTapiCallManager.btnHangupClick(Sender: TObject);
var
TempStringList : TStringList;
begin
TempStringList := TStringList.Create;
if not TAPICntrl.ShutdownManager then
begin
Memo.Lines.Assign(TStrings(TempStringList));
Memo.Invalidate;
TempStringList.Free;
Exit;
end
else
begin
Memo.Lines.Assign(TStrings(TempStringList));
Memo.Invalidate;
TempStringList.Free;
btnHangup.Enabled := false; // disable the hangup button
btnDial.Enabled := true; // enable the dial button
end;
end;
procedure TTapiCallManager.SetBitmap(Image: TImage; Index: integer);
var
Bmp: TBitMap;
begin
Bmp := TBitMap.Create;
try
ImageList.GetBitMap(Index, Bmp);
Image.Picture.Bitmap := Bmp;
finally
Bmp.Free;
end;
end;
procedure TTapiCallManager.cboxDevicesChange(Sender: TObject);
begin
TAPICntrl.Dev := cboxDevices.ItemIndex;
end;
procedure TTapiCallManager.cbLineMapperClick(Sender: TObject);
begin
if cbLineMapper.Checked then
TAPICntrl.AutoSelectLine := True else
TAPICntrl.AutoSelectLine := False;
cboxDevices.Enabled := not TAPICntrl.AutoSelectLine;
if TAPICntrl.AutoSelectLine then
TAPICntrl.Dev := 0
else
TAPICntrl.Dev := cboxDevices.ItemIndex;
end;
procedure TTapiCallManager.PhoneNumChange;
begin
TAPICntrl.PhoneNumber := ePhoneNum.Text;
end;
procedure TTapiCallManager.cboxMediaMo